<template>
    <Modal  :closable="false" v-model="visible" :title="titleName(title)">
        <Form ref="form" v-if="visible" class="formList" :model="form" label-position="top" :rules="rules">

            <FormItem label="对象" required prop="orgName">
                <Input type="text" v-model="form.orgName" placeholder="请输入对象" class="inputBorder"></Input>
            </FormItem>
            <FormItem label="简称" required prop="orgAbbreviation">
                <Input type="text" v-model="form.orgAbbreviation" placeholder="请输入简称" class="inputBorder"></Input>
            </FormItem>
            <!-- <FormItem label="产品名称" required prop="product_id">
                <Select v-model="form.product_id" placeholder="请输入产品名称`">
                <Option v-for="(item,index) in materialList" :key="index.id" :value="item.id" :label="item.name"></Option>
              </Select>
                
            </FormItem> -->
            
           
        </Form>
        <div slot="footer" v-if="visible">
            <Button type="default" @click="closeModal">取消</Button>
            <Button type="primary" @click="handleSubmit('form')">确定</Button>
        </div>
    </Modal>
</template>

<script>
export default {
    name: "CreateOrUpdateModal",
    props: {
        visible: Boolean,
        form: Object,
        title: String,
        handleAddSubmit: Function,
        closeModals: Function,
    },
    data() {
        return {
            rules: {
                orgName: [
                    { required: true, message: '请输入对象', trigger: 'blur' }
                ],
                orgAbbreviation: [
                    { required: true, message: '请输入简称', trigger: 'blur' }
                ],
          
            },
        };
    },
    methods: {
        titleName(type){
      const titles = {
      add: '新增节点',
      edit: '修改节点',
      next: '新增子节点'
    };

    return titles[type] || '未知操作';
           
        },
        closeModal() {
           this.closeModals()
        },  
        handleSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.handleAddSubmit(formName,);
                }
            })

        },
    },
};
</script>

<style scoped>
.formList {}
</style>